import { getDetailsByIdApi } from "@/api/client/documentManagement/waybillManagement";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<ClientWaybillManagement.MakeInvoice>({
    id: 0,
    waybillNum: "",
    materialQualityId: "",
    addressType: "",
    warehouseCode: "",
    city: "",
    isElectrification: 0,
    isMagnetic: 0,
    customerOrderNumber: "",
    amazonReferenceId: "",
    state: "",
    zipCode: "",
    receiverName: "",
    receiverEmail: "",
    receiverPhone: "",
    receiverCompany: "",
    address: "",
    addressTwo: "",
    addressThree: "",
    invoicementRemark: "",
    customsDeclarationType: "",
    customsTaxesType: "",
    customsClearanceType: "",
    customsAllBoxNum: 0,
    dedupBoxNum: 0,
    vatTaxNumber: "",
    preOrderShipmentBox: [],
    countryRegionName: "",
    channelName: "",
    remark: "",
    declarationTypeList: [],
    taxesTypeList: [],
    bizPreOrderShipmentFileResDtoList: []
  });
  const loading = ref<boolean>(false);
  const init = (id: string) => {
    loading.value = true;
    return getDetailsByIdApi(id)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          Object.assign(formState, data);
        }
      })
      .finally(() => (loading.value = false));
  };
  return {
    formState,
    loading,
    init
  };
}
